
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.system.service.IBuyCreditsService"%>
<%@page import="com.sinba.common.system.dto.BuyCreditsQueryDTO"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
	if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/buyMain.jsp");
	return;
	}
	ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	
	BuyCreditsQueryDTO qdto = new BuyCreditsQueryDTO(); 
	qdto.setOperationsCenter((String)session.getAttribute("loginName"));
	IBuyCreditsService buyCreditsService = (IBuyCreditsService)ac.getBean("buyCreditsService");
	int pages = 1;
	if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
		pages = Integer.parseInt(request.getParameter("pages"));
	}
	int rows = 10;
	int start = ( pages - 1 ) * rows;
	qdto.setStart(start);
	qdto.setLimit(rows);
	PageDTO pageDTO = buyCreditsService.findBuyCreditsPager(qdto, "desc", "createTime");
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
	request.setAttribute("pageDTO",pageDTO);
	
	request.setAttribute("loginName",(String)session.getAttribute("loginName"));
	
%>
<fmt:setLocale value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
	<fmt:setBundle basename="i18n.itilbase"/>
	<c:set var="lang" value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta charset="UTF-8">
<title>我的买入</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />


<!-- Bootstrap framework -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" />
<!-- breadcrumbs-->
	<link rel="stylesheet" href="lib/jBreadcrumbs/css/BreadCrumb.css" />
<!-- main styles -->
    <link rel="stylesheet" href="css/sub_page_main_style.css" />

<!--[if lte IE 8]>
    <link rel="stylesheet" href="css/ie.css" />
    <script src="js/ie/html5.js"></script>
    <script src="js/ie/respond.min.js"></script>
<![endif]-->

</head>
<body style="height:800px">

<!-- 主体内容 -->
<div id="contentwrapper">
	<div class="main_content">
		 <nav>
            <div id="jCrumbs" class="breadCrumb module">
                <ul>
                    <li>
                        <a href="main.jsp"><i class="icon-home"></i></a>
                    </li>
                    <li>
                        <a href="#"><fmt:message key="i18n.moneyManage"/></a>
                    </li>
                    <li>
                        <a href="#">我的买入列表</a>
                    </li>
                </ul>
            </div>
         </nav>	
         
	<div class="listCont">
    	<div class="listTable lttno">

    		<!-- 提现记录 -->
		        <div style="padding: 5px;" align="left" >
		        	<form id="cashBusiness_form">
		        	<table width="100%" id="tr_cashBusiness_table" class="table table-bordered table-striped">
	        			<tr>
	        				<th>卖出会员</th>
	        				<th>金额</th>
	        				<th>卖出时间</th>
	        				<th>账号类型</th>
	        				<th>账号</th>
	        				<th>微信</th>
	        				<th>手机</th>
	        				<th>状态</th>
	        				<th>操作</th>
	        			</tr>
		        		<c:if test="${pageDTO.totalSize eq 0}">
						<tr><td colspan="10" align="center"><fmt:message key="i18n.noData"/>!</td></tr>
						</c:if>	
						<c:if test="${pageDTO.totalSize ne 0}">
							<c:forEach items="${pageDTO.data}" var="data">
							<tr>
								<td>${data.loginName }(${data.loginUserName})</td>
								<td>${data.buyMoney*0.95 }</td>
								
								<td><fmt:formatDate value="${data.buyTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td>${data.accountType}</td>
								<td>${data.bankAccount}</td>
								<td>${data.weiXin}</td>
								<td>${data.mobileNo}</td>
								<td>
									<c:if test="${data.status eq 0}"><span style="color:red;">待买入</span></c:if>
									<c:if test="${data.status eq 1}">请打款给卖出会员，并让卖出会员进行确认操作!</c:if>
									<c:if test="${data.status eq 2}"><span style="color:green;">买入成功</span></c:if>
								</td>
								<td>
									<c:if test="${data.status eq 1}">
											<a id="cleanBuy_${data.id}" href="javascript:cleanBuy('${data.id}')">取消买入</a>
									</c:if>
								</td>
							</tr>
							</c:forEach>
						</c:if>      		
		        	</table>
		        	</form>
		        	
		        	<!-- 分页 start -->
					<div class="page">
					<div id="tr_recommendGrid_pager" class="page_r">
						<ul>
							<li><a href="myBuy.jsp?pages=1"><fmt:message key="i18n.firstPage"/></a></li>
							<c:if test="${pageDTO.page!=1}">
								<li><a href="myBuy.jsp?pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a></li>
							</c:if>
							<li><a>${pageDTO.page}/${pageDTO.total}</a></li>
							<c:if test="${pageDTO.page+1<=pageDTO.total}">
								<li><a href="myBuy.jsp?pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a></li>
							</c:if>
							<li><a href="myBuy.jsp?pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a></li>
							<li><a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a></li>
						</ul>
					</div>
					</div>
					<!-- 分页 end  -->
		        	
		        	
				<!-- end 提现记录 -->
    		
    			<form action="buyCredits!buyCredits.action" id="buyCredits_form" method="post">
				</form>
				
				<form action="buyCredits!buyCredits.action" id="cleanBuy_form" method="post">
				</form>
    	</div>
    </div>	
</div>
				
</div>
</div>

<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../scripts/user/common.js"></script>
<script>

var isclick=true;
function buyCredits(id,loginName){
	
	$('#buyCredits_form').html("<input type='hidden' name='pageUrl' value='myBuy.jsp' />"+
			"<input type='hidden' name='buyCreditsDTO.operationsCenter' value='"+loginName+"' />"+
			"<input type='hidden' name='buyCreditsDTO.id' value='"+id+"' />");
	if(confirm('Are you sure you want to buy(是否确定要买入)?')){
		$('#buyCreditsr_'+id).attr("disabled",true);
		if(isclick){
			isclick=false;
			$('#buyCredits_form').submit();
		}else{
			alert('操作过于频繁，请稍后再操作!');
		}
		
	}
}

function cleanBuy(id){
	
	$('#cleanBuy_form').html("<input type='hidden' name='pageUrl' value='myBuy.jsp' />"+
			"<input type='hidden' name='buyCreditsDTO.optType' value='cleanBuyCredits' />"+
			"<input type='hidden' name='buyCreditsDTO.id' value='"+id+"' />");
	if(confirm('Confirm that you want to cancel buy it(确认要取消买入吗)?')){
		$('#cleanBuy_'+id).attr("disabled",true);
		if(isclick){
			isclick=false;
			$('#cleanBuy_form').submit();
		}else{
			alert('操作过于频繁，请稍后再操作!');
		}
		
	}
}
</script>


</body>
</html>